package com.snap.update.manager;


import android.content.Context;

import com.snap.update.utils.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ConfigManager {

    public final static String soFileName = "libserial_port.so";

    private static ConfigManager sInstance = new ConfigManager();
    private ExecutorService singlePool = Executors.newSingleThreadExecutor();

    private ConfigManager() {
    }

    public static ConfigManager getInstance() {
        return sInstance;
    }

    /**
     * 初始化 配置路径 异步加载配置到内存中
     */
    public void init(Context context) {
        //把asset目录下的so文件复制到  app内存files目录下，以备loadLibrary加载so失败时，加载这儿的so文件
        singlePool.execute(() -> {
            try {
                File soFile = new File(context.getFilesDir(), soFileName);
                InputStream is = context.getAssets().open(soFileName);
                FileUtils.copyInputStreamToFile(is, soFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

    }

}